package com.ruoyi.system.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.R;
import com.ruoyi.system.domain.PmsPlanVo;
import com.ruoyi.system.domain.PmsSkuInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.system.domain.PmsPlan;
import com.ruoyi.system.service.IPmsPlanService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 采购需求Controller
 *
 * @author ruoyi
 * @date 2025-01-15
 */
@RestController
@RequestMapping("/plan")
@CrossOrigin
public class PmsPlanController extends BaseController
{
    @Autowired
    private IPmsPlanService pmsPlanService;

    /**
     * 查询采购需求列表
     */
    @GetMapping("/list")
    public TableDataInfo list(PmsPlan pmsPlan)
    {
        startPage();
        List<PmsPlan> list = pmsPlanService.selectPmsPlanList(pmsPlan);
        return getDataTable(list);
    }

    /**
     * 查询采购需求列表
     */
    @GetMapping("/findlist")
    public TableDataInfo findlist(PmsPlanVo pmsPlanVo)
    {
        startPage();
        List<PmsPlanVo> list = pmsPlanService.selectPmsPlanVoList(pmsPlanVo);
        return getDataTable(list);
    }

    /**
     * 导出采购需求列表
     */
    @RequiresPermissions("system:plan:export")
    @Log(title = "采购需求", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PmsPlan pmsPlan)
    {
        List<PmsPlan> list = pmsPlanService.selectPmsPlanList(pmsPlan);
        ExcelUtil<PmsPlan> util = new ExcelUtil<PmsPlan>(PmsPlan.class);
        util.exportExcel(response, list, "采购需求数据");
    }

    /**
     * 获取采购需求详细信息
     */
    @RequiresPermissions("system:plan:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(pmsPlanService.selectPmsPlanById(id));
    }

    /**
     * 新增采购需求
     */
    @Log(title = "采购需求", businessType = BusinessType.INSERT)
    @PostMapping
    public R add(@RequestBody PmsSkuInfo pmsSkuInfo)
    {
        R ajaxResult = pmsPlanService.insertPmsPlan(pmsSkuInfo);
        return R.ok(ajaxResult);
    }

    /**
     * 修改采购需求
     */
    @RequiresPermissions("system:plan:edit")
    @Log(title = "采购需求", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PmsPlan pmsPlan)
    {
        return toAjax(pmsPlanService.updatePmsPlan(pmsPlan));
    }

    /**
     * 删除采购需求
     */
    @RequiresPermissions("system:plan:remove")
    @Log(title = "采购需求", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(pmsPlanService.deletePmsPlanByIds(ids));
    }
}
